define(function(require, exports, module) {
	"require:nomunge,exports:nomunge,module:nomunge";


	require("../../custom/base/component-core.js");
	
	var async = require("../../custom/base/component-async.js");
	
	var validate = require("../../custom/base/component-validate.js");
		
	require("../../custom/base/component-md5.js");

	
	exports.init=function(m) {
		
		window.$ldh_base = m;
		
	
	};
	
	//截取字符串,超出长度用省略号表示
	exports.subString=function(value,length){
		
		if(value.length>length){
			
			value=value.substring(0,length)+"...";
			
		}else if(value.length=length){
			
			value=value;
		}
		
		return value;
		
	};
	
	//替换
	exports.replaceQuotationMarks=function(str)
	{
	    var regex = new RegExp(" ", "g");
	    return str.replace(regex, "");
	};
	
	//保存cookie
	exports.setCookie=function(key,value){
		
		
		   if(document.URL.indexOf("storeme.cn")>=0){
		    	
			   $.cookie(key,value, {expires:30,path:'/',domain: ".storeme.cn"});
			 
		   }else if(document.URL.indexOf("jujie.xyz")>=0){
		    	
				 $.cookie(key,value, {expires:30,path:'/',domain: ".jujie.xyz"});
				 
		   }else{
			   
			   $.cookie(key,value, {expires:30,path:'/'});
			 
		   }
		// $.cookie(key,value, {expires:30,path:'/'});
		
	};
	
	//获取cookie
	exports.getCookie=function(key){
		
		if(key=="lng"){
			
			return $.cookie(key)==null?"113.355747":$.cookie(key);
		}else if(key=="lat"){
			
			return $.cookie(key)==null?"23.127191":$.cookie(key);
		}else{
			
			
			
			return validate.isNull($.cookie(key))?"":$.cookie(key);
		}
		
	};
	
	//清除cookie
	exports.clearCookie=function(key){
		
	

		   if(document.URL.indexOf("storeme.cn")>=0){
		    	
			   $.cookie(key, null, {path : '/',domain: ".storeme.cn"});
			   
		   }else if(document.URL.indexOf("jujie.xyz")>=0){
		    	
			   $.cookie(key, null, {path : '/',domain: ".jujie.xyz"});
				 
		   }else{
			   
				$.cookie(key, null, {path : '/'});
		   }
		   
	};
	
	//显示完整的图片
	exports.ResizeImage=function(id) {

	var img = document.getElementById(id);
	if(img == null){
		return;
	}
	
	


	var widthHeightRate = img.width / img.height;

		if (widthHeightRate >1) {
		
		img.width = (img.width > 234) ? "234" : img.width;
		
		img.height = img.width / widthHeightRate;
		
		
		} else {
		img.height = (img.height > 234) ? "234" : img.height;
		img.width = img.height * widthHeightRate;
		
		}


	};
	
	//验证登录状态
	exports.validateLoginStatus=function(data){
		
		if(data.code == "-9999999999"){
			exports.loginShow();
			return false;
		}
		
		return true;
	};
	
	//通过用户代码验证登录状态
	exports.validateLoginStatusByUserId=function(fun){
		var userId=$("#session_userid").val();
		if(validate.isNull(userId)){
			exports.loginShow(fun);
			return false;
		}
		return true;
	};
	
	//获取滚动高度
	exports.getMyScrollTop=function(){
		
		return myScrollTop;
	};
	
	//等待加载
	exports.showLoading=function(){
		
		 //显示加载器.for jQuery Mobile 1.2.0
	    $.mobile.loading('show', {
	        text: '加载中...', //加载器中显示的文字
	        textVisible: true, //是否显示文字
	        theme: 'e',        //加载器主题样式a-e
	        textonly: false,   //是否只显示文字
	        html: ""           //要显示的html内容，如图片等
	    });
	};
	//设置页面来源
	exports.setFromPage=function(fromPage){
		
		this.fromPage=fromPage;
		
	};
	
	//获取页面来源
	exports.getFromPage=function(){
		
		return this.fromPage;
		
	};
	
	//移除加载
	exports.cancelLoading=function(){		

	    //隐藏加载器
	    $.mobile.loading('hide');
	};
	
	//关闭登录等
	exports.closeDialog=function(){
		
		alert("关闭登录框");
		
	};
	
	//个人中心
	exports.ucenter=function(){
		
		get2post(ctx+"/v1/pages/ucenter/ucenter.jsp","_blank");
		
	};
	
	//切换账户
	exports.changeAccount=function(){
		
		exports.loginShow();
		
	};
	
	//退出登录
	exports.logout=function(){
		
		var params={
				"userId":exports.getCookie("userId"),
				"deviceId":"",
				"sign":MD5(exports.getCookie("userId"))
			};
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Login/logout.do", params));
			
			
			exports.clearCookie("userId");
			exports.clearCookie("userName");
			exports.clearCookie("mobile");
			exports.clearCookie("loginSign");
			
			
			window.location.href=ctx+"/h5/index.shtml";

			
		}))().start();
						
	};
	
	//登录
	exports.login=function(){

		var mobile=$("#login_mobile").val();
				
		var password=$("#login_password").val();
		
		if(!validate.isMobile(mobile)){
			
			showTips("请填写正确的手机号码");
		
			return;
		}
		
		if(validate.isNull(password)){
			
			showTips("请输入登录密码");
			
			return;
		}

		/*if("123456" == password || "000000"== password || "111111"== password){
			showTips("密码过于简单，请登录后马上修改密码！");
		}*/
		
		var params={
			"userName":mobile,
			"password":MD5(password),
			"sessionId":"",
			"sign":MD5(mobile+""+MD5(password)+"")
		};
		
		exports.showLoading();
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Login/login.do", params));

			if(data.code =="1"){
				//登录成功
			
				showTips("登录成功");
				
				exports.setCookie("userId",data["userId"]);
				exports.setCookie("userName",data["userName"]);
				exports.setCookie("mobile",data["mobile"]);
				exports.setCookie("loginSign",data["loginSign"]);
				
				if(exports.getFromPage()=="mine"){
					window.location.href="#ldhMine";
				}else if(exports.getFromPage()=="cart"){
					window.location.href="#ldhCart";
				}else if(exports.getFromPage()=="ldhStore"){
					exports.showDiv("#ldhStore","","?shopId="+exports.getParameter("shopId"));

				}else if(exports.getFromPage()=="ldhGoods"){
					exports.showDiv("#ldhGoods","","?merchandiseId="+exports.getParameter("merchandiseId"));

				}else{
					window.location.href="#ldhHome";
				}
				
			}else{
				
				showTips(data.message);
				
			}
			exports.cancelLoading();
			
		}))().start();
		
	};
	

	//未登录的显示
	exports.noLoginShow=function(){
		
		

	};
	
	//已登录的显示
	exports.hasLoginShow=function(){
		
		
		
	};
	

	//同意注册协议
	exports.agree=function(obj){
		
		if($(obj).hasClass("checked")){
			
			$(obj).removeClass("checked");
			
			$("#cb_agree").val("0");
			
		}else{
			
			$(obj).addClass("checked");
			
			$("#cb_agree").val("1");
		}
				
	};
	
	//注册
	exports.register=function(){

		var mobile=$("#register_mobile").val();
		
		var validateCode=$("#register_validateCode").val();
		
		var password=$("#register_password").val();
		
		if(!validate.isMobile(mobile)){
			
			showTips("请填写正确的手机号码");
			
			return;
		}
		
		if(validate.isNull(validateCode)){
			
			showTips("请输入短信验证码");
			
			return;
		}

		if(!validate.isLoginPassword(password)){
			
			showTips("密码必须为6-20位数字，字母，符号组合");
			
			return;
		}
		
		if($("#cb_agree").val()!="1"){
			
			showTips("请勾选《云便利商店注册协议》");
			
			return;
		}
				
		var params={
				
			"mobile":mobile,
			
			"validateCode":validateCode,
			
			"password":MD5(password)
			
		};
		
		exports.showLoading();
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Reg/register.do", params));

			if(data.code =="1"){
				//注册成功,自动登录
				
				showTips("注册成功,正在登录...");
				
				$("#login_mobile").val(mobile);
				
				$("#login_password").val(password);
				
				exports.login();
				
			}else{
				
				showTips(data.message);
				
			}

			exports.cancelLoading();
			
			
		}))().start();
		
	};
	

	//验证手机号是否注册过
	exports.validateMobile=function(inputId,btnId){
		
		var mobile = $(inputId).val();
		
		if(!validate.isMobile(mobile)){
			
			showTips("请填写正确的手机号码");
			
			return;
		}
	
		$(btnId).attr("disabled", "disabled");

		exports.showLoading();
		
		if(btnId=="#btn_find_request_code"){
			
			sendMessage(mobile,btnId);
			
			return;
		}

		var params={
				"sign":MD5(mobile+"_sms_"),
				"mobile":mobile
			};
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Reg/validateMobile.do", params));
			
			if(data.code == "1"){
				//未注册,发送验证码
				sendMessage(mobile,btnId);
			}else{
				
				showTips(data.message);
				
				$(btnId).html("免费获取验证码");
				
				//如果该手机已注册,则可以马上重新验证
				$(btnId).attr("disabled", false);
			}
			
			exports.cancelLoading();

		}))().start();
		
	};
	
	//发送短信验证码
	function sendMessage(mobile,btnId){
		
		var params={
				"sign":MD5(mobile+"_sms_"),
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data;
			
			if(btnId=="#btn_find_request_code"){
				
				data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/sendValidateCode.do", params));

			}else{
				
				
				data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Reg/sendValidateCode.do", params));

			}
			
			
			if(data.code == "1"){
				
				task(btnId).start();
				
			}else{
				
				//如果获取验证码失败,则可以马上重新获取
				$(btnId).attr("disabled", false);
				
				$(btnId).html("免费获取验证码");
				
				showTips(data.message);
			
			}

		}))().start();
	}
	
	//倒计时
	var wait = 90;
	
	var tips_task = eval(Wind.compile("async", function (btnId) {
		wait--;
	    $await(Wind.Async.sleep(1000));
	    if(wait==0){
	    	//倒计时完成,发送验证码按钮生效
	    	$(btnId).attr("disabled", false);
	    	$(btnId).html("免费获取验证码");
	    	
	    }else{
	    	
	    	$(btnId).html(wait + "秒后重新获取");
	    }
	    
	}));
	
	var task = eval(Wind.compile("async", function (btnId) {
	    $await(tips_task(btnId));
	    if(wait>0){
	      task(btnId).start();
	    }else{
	    	wait=90;
	    }
	}));

	//找回密码框出现
	exports.forgotShow=function(){	
		$(".ldh-loginBox").show();
		var forgot_h=$("#ldh-forgot").outerHeight();
		$("#ldh-forgot").css("top",-forgot_h);
		$("#ldh-forgot").show().siblings(".ldh-loginDiv").hide();	
		$("#ldh-forgot").animate({top:230},300);	
		exports.forgotHide();	
	};
	
	//找回密码框消失
	exports.forgotHide=function(){
		$(document).on("click",".ldh-loginBox",function(event){
			var _target=$(event.target).parents();
			if(!_target.hasClass("ldh-loginBox")){
				var win_height=$(window).height();
				$("#ldh-forgot").animate({top:win_height},300);	
				setTimeout(function(){$(".ldh-loginBox").hide();$("#ldh-forgot").stop(true,true)},300);	
			}		
		})
	};
	
	//校验验证码是否正确
	exports.getValidate=function(){
		

		var mobile=$("#find_mobile").val();
		
		var validateCode=$("#find_validateCode").val();
		
		if(!validate.isMobile(mobile)){
			
			$("#tip_find").html("请填写正确的手机号码");
			
			return;
		}
		
		if(validate.isNull(validateCode)){
			
			$("#tip_find").html("请输入短信验证码");
			
			return;
		}
		
		
		exports.showLoading("#btn_find_next",22,true);

		$("#tip_find").html("");
		
		var params={
				"validatecode":validateCode,
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/getValidateCode.do", params));
			
			if(data.code == "1"){
				
				exports.changepwdShow();
				
				
				
			}else{
				
				$("#tip_find").html(data.message);
			
			}
			
			$("#btn_find_next").html("下一步");

		}))().start();
		
	};

	//修改密码
	exports.reLoginPwd=function(){
		
		var find_password=$("#find_password").val();
		
		var find_confirm_password=$("#find_confirm_password").val();
		
		var mobile=$("#find_mobile").val();
		
	
		if(!validate.isLoginPassword(find_password)){
			
			$("#tip_re_pwd").html("密码必须为6-20位数字，字母，符号组合");
			
			return;
		}
		
		if(find_confirm_password!=find_password){
			
			$("#tip_re_pwd").html("两个密码必须一致");
			
			return;
		}
		
		$("#tip_re_pwd").html("");
		
		exports.showLoading("#btn_re_pwd",22,true);
		
		var params={
				"password":MD5(find_password),
				"mobile":mobile
			};

		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Login/reLoginPwd.do", params));
			
			if(data.code == "1"){
				
				$(".ldh-loginBox").hide();
				
				$("#find_password").val("");
				
				$("#find_confirm_password").val("");
				
				$("#find_mobile").val("");
				
				$("#find_validateCode").val("");
				
				
			}else{
				
				$("#tip_re_pwd").html(data.message);
			
			}
			

			$("#btn_re_pwd").html("确定");

		}))().start();
		
	};
	

	//关闭按钮
	exports.loginBoxClose=function(){
		$(".ldh-loginBox").click();	
	};
	

	//查询是否开店
	exports.getIsOpenShop=function(shopId){
		
		
		if(shopId==""){
			
			eval(Wind.compile("async", function() {

				var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopweb/Shop/getIsOpenShop.do", ""));
				
				if(data.code=="1"){
					
					if(data.shopId!=""){
			            
						
						exports.showBackStage();
						
						
					
					}else{
						
						exports.showOpenStore();
						
					}
				}else{
					
					exports.showOpenStore();

				}


			}))().start();
		}else{
			
			exports.showBackStage();

			
		}
		
	};
	
	//显示"我要开店"
	exports.showOpenStore=function(){
		
		
				
		$("#div_store").html('<a href=javascript:$ldh_base.gotoOpenStore("openStore")><button type="button">我要开店</button></a>');
		
		//$("#div_store").html('');
		
		//$("#div_store").hide();
		
	};
	
	//显示"商家后台"
	exports.showBackStage=function(){
		
		$("#div_store").html('<a rel="external" href="'+ctx+'/admin/index.jsp" target="_blank"><button type="button">商家后台</button></a>');
		
		$("#div_store").show();
	};
	
	//进入开店页面
	exports.gotoOpenStore=function(fun){
		
		
		//必须登录且没有开店的															
		if(exports.validateLoginStatusByUserId(fun) && validate.isNull($("#session_shopid").val())){
			
			
			window.location.href=ctx+"/v1/pages/store/openStore.jsp";
			
		}
		
		
	};
	
	
	// 获取特色
	exports.getSpeHtml=function(speId){
		
		var speHtml="";
		
		if(speId!="" && speId.indexOf(",")>0){
			var strArray=speId.split(",");
			
			for(var j=0;j<strArray.length;j++){
				
				speHtml+=getSpeItem(strArray[j]);
				
			}
		}else if(speId!=""){
			
			speHtml+=getSpeItem(speId);
		}
		
		if(speHtml=="")
			speHtml="";
		
		return speHtml;
		
	};
	
	//获取一项特色
	function getSpeItem(type){
		
		if(type=="")
			return;
		
		var speHtml="";
		
		switch (parseInt(type)) {
		case 1:
			speHtml+='<i class="icon-fu" title="在线支付"></i>';
			break;
		case 2:
			speHtml+= '<i class="icon-xian" title="现金支付"></i>';
			break;
		case 3:
			speHtml+= '<i class="icon-shi" title="实体店"></i>';
			break;
		case 4:
			speHtml+= '<i class="icon-tao" title="淘宝店"></i>';
			break;
		case 5:
			speHtml+= '<i class="icon-v" title="营业执照"></i>';
			break;
		case 6:
			speHtml+= '<i class="icon-v2" title="卫生许可证"></i>';
			break;
		case 7:
			speHtml+= '<i class="icon-hui" title="有优惠"></i>';
			break;
		default:
			break;
		}
		
		return speHtml;
	}
	
	// 获取特色
	exports.getSpeListHtml=function(speId){
		
		var speHtml="";
		
		if(speId!="" && speId.indexOf(",")>0){
			var strArray=speId.split(",");
			
			for(var j=0;j<strArray.length;j++){
				
				speHtml+=getSpeItemList(strArray[j]);
				
			}
		}else if(speId!=""){
			
			speHtml+=getSpeItemList(speId);
		}
		
		if(speHtml=="")
			speHtml="";
		
		return speHtml;
		
	};
	
	//获取一项特色
	function getSpeItemList(type){
		
		if(type=="")
			return;
		
		var speHtml="";
		
		switch (parseInt(type)) {
		case 1:
			speHtml+='<li><i class="icon-fu"></i><span>支持在线支付</span></li>';
			break;
		case 2:
			speHtml+= '<li><i class="icon-xian"></i><span>支持现金支付</span></li>';
			break;
		case 3:
			speHtml+= '<li><i class="icon-shi"></i><span>实体店</span></li>';
			break;
		case 4:
			speHtml+= '<li><i class="icon-tao"></i><span>淘宝店</span></li>';
			break;
		case 5:
			speHtml+= '<li><i class="icon-v"></i><span>营业执照</span></li>';
			break;
		case 6:
			speHtml+= '<li><i class="icon-v2"></i><span>卫生许可证</span></li>';
			break;
		case 7:
			speHtml+= '<li><i class="icon-hui"></i><span>有优惠</span></li>';
			break;
		default:
			break;
		}
		
		return speHtml;
	}
	
		
	//保存搜索历史
	exports.saveSearchHistoryCookie=function(name,lng,lat) {
		try {
			
			var cookieList;
			var cookie_item;
			
			if(validate.isNull(exports.getCookie("cookieList")) || typeof(exports.getCookie("cookieList"))=="undefined"){
				//如果历史记录为空,新家一条记录
				cookieList=new Array();
				cookie_item = new Object();
				cookie_item.name=name;
				cookie_item.lng=lng;
				cookie_item.lat=lat;
				cookieList.push(cookie_item);
				exports.setCookie("cookieList",JSON.stringify(cookieList));

				
			}else{
				
				
				var cookieListData=JSON.parse(exports.getCookie("cookieList"));
				
				cookieList=new Array();
				
				var isExits=false;
				
				for(var i=0;i<cookieListData.length;i++){
										
					if(name!=cookieListData[i].name){
						cookie_item = new Object();
						cookie_item.name=cookieListData[i].name;
						cookie_item.lng=cookieListData[i].lng;
						cookie_item.lat=cookieListData[i].lat;
						cookieList.push(cookie_item);
						
					}else{
						
						isExits=true;
					}
				}
				
				//如果历史记录不存在这条记录, 则把该记录添加进去
				if(!isExits){
					
					cookie_item = new Object();
					cookie_item.name=name;
					cookie_item.lng=lng;
					cookie_item.lat=lat;
					cookieList.push(cookie_item);
				}
				
				exports.setCookie("cookieList",JSON.stringify(cookieList));

				
			}
			
			

		} catch (e) {
		}
		
		exports.getSearchHistoryCookie();
	};
	
	//获取最近搜索列表
	exports.getSearchHistoryCookie=function() {
		
		try {

			
			if(!validate.isNull(exports.getCookie("cookieList"))){
				
				var cookieListData=JSON.parse(exports.getCookie("cookieList"));
				
				$("#historyList").html("");
				
				var length=cookieListData.length;
				
				if(length>10)
					length=10;
				
				for(var i=0;i<length;i++){
					
						var name=exports.replaceQuotationMarks(cookieListData[i].name);
						
						$("#historyList")
								.prepend(
										'<li onclick=$ldh_base.clickHistoryItem("'+name+'","'+cookieListData[i].lng+'","'+cookieListData[i].lat+'",event)><span   title="'
												+ name
												+ '">'
												+ exports.subString(name,9)
												+ '</span><i class="icon_close" onclick=$ldh_base.clearHisItemCookie("'
												+ name + '")>&nbsp;&nbsp;&nbsp;&nbsp;×</i></li>');
				}
				
			}
			

		} catch (e) {

		}

	};

	//点击历史记录
	exports.clickHistoryItem=function(address,lng,lat,event){
		
		/*
		var _target=$(obj).find("i");
	
		
		if(_target.hasClass("icon_close"))
			return;*/
		
		//var _target=$(event.target);
		var _target= event.srcElement ? $(event.srcElement):$(event.target);

		
		if(_target.hasClass("icon_close"))
			return;
		
		exports.setCookie("address",address);
		
		exports.setCookie("lng",lng);
		
		exports.setCookie("lat",lat);
		
		$("#address").html(exports.subString(exports.getCookie("address"),10));
		
		$("#address").attr("title",exports.getCookie("address"));
						
		if(exports.getFromPage()=="index"){
			
			$ldh_index.getShopListByType();
			
		}else if(exports.getFromPage()=="shopList"){
			
			//$ldh_shop_list.getShopList();
			
		}
		
	};
	
	//清除某一个Cookies
	exports.clearHisItemCookie=function(name) {

		/*var _target=$(obj);
		
		if(!_target.hasClass("icon_close"))
			return;
		*/
		
		try {
			if(!validate.isNull(exports.getCookie("cookieList")) && typeof(exports.getCookie("cookieList"))!="undefined"){
				
					var cookieListData=JSON.parse(exports.getCookie("cookieList"));
					
					var cookieList=new Array();
					
					for(var i=0;i<cookieListData.length;i++){
						if(name!=cookieListData[i].name){
							var cookie_item = new Object();
							cookie_item.name=cookieListData[i].name;
							cookie_item.lng=cookieListData[i].lng;
							cookie_item.lat=cookieListData[i].lat;
							cookieList.push(cookie_item);
						}
					}
					exports.setCookie("cookieList",JSON.stringify(cookieList));

			}
			

		} catch (e) {

		}
		
		exports.getSearchHistoryCookie();

	};

	//清除Cookies
	exports.clearHisCookie=function() {
		exports.clearCookie("cookieList");
		$("#historyList").html("");
	};
	

	

	//选择地址层出现
	exports.myLocation=function(){
	
		$(".ldh-location").show();	
		
		$("#ldh-inputAdress").focus();
		
		exports.showCityPlaceholder();
		
		if(!validate.isNull(exports.getCookie("lng")) && !validate.isNull(exports.getCookie("lat"))){
			
			$("#btn_close_location").show();
		}else{
			$("#btn_close_location").hide();
		}
		
		//$(".ldh-location").fadeIn();
	};
	
	//选择地址层消失
	exports.myLocationHide=function(){
		$(".ldh-location").hide();	
		//$(".ldh-location").fadeOut();
		$("#inputSearch").focus();
	};
	
	
	//设置城市
	exports.setCity=function(cityId, cityName) {

		$("#cityName").html(cityName);

		exports.setCookie("cityId",cityId);
		
		exports.setCookie("cityName",cityName);
		
		$("#ldh-city").removeClass("on");
		
		exports.showCityPlaceholder();
	};
	
	//显示城市
	exports.showCity=function(){
		
		$("#ldh-city").addClass("on");
	};
	
	//切换城市提示
	exports.showCityPlaceholder=function(){
		
		var cityId=exports.getCookie("cityId");
		
		if(cityId=="440100"){
			
			$("#ldh-inputAdress").attr("placeholder","输入街道/地标/商圈.例如:广州塔");
			
			//$("#recommendAddress").html('<li><span>广州塔</span></li>');
			$(".ldh-banner").show();
		
		
			exports.initAd();
		
			
			
		}else if(cityId=="440400"){
			
			$("#ldh-inputAdress").attr("placeholder","输入街道/地标/商圈.例如:华发新城");
			
			//$("#recommendAddress").html('<li><span>华发新城</span></li>');
			
			$(".ldh-banner").hide();
			
		}else if(cityId=="110100"){
			
			$("#ldh-inputAdress").attr("placeholder","输入街道/地标/商圈.例如:朝阳大厦等");
			
			$(".ldh-banner").hide();
		}
	};

	
	//保存搜索的地址
	exports.setSearchAddress=function(address,lng,lat){
		
		exports.setCookie("address",address);
		
		exports.setCookie("lng",lng);
		
		exports.setCookie("lat",lat);
		
		$("#address").html(exports.subString(exports.getCookie("address"),10));
		
		$("#address").attr("title",exports.getCookie("address"));
		
		exports.myLocationHide();
		
		exports.saveSearchHistoryCookie(address,lng,lat);
		
		if(exports.getFromPage()=="index"){
			
			$ldh_index.getShopListByType();
			
		}else if(exports.getFromPage()=="shopList"){
			
			//$ldh_shop_list.getShopList();
			
		}
		
	};
	
	//选择搜索出来的地址
	exports.selectSearchItem=function(title,lng,lat){

		$("#ldh-inputAdress").val(title);
		
		$(".ldh-addressGroup").hide();
		
		exports.setSearchAddress(title,lng,lat);
		
	};
	
	


	//跳转到商家主页
	exports.jumpToShopIndex=function(shopId){
		
		//get2post(ctx+"/v1/pages/shop/shopIndex.jsp?shopId="+shopId,"_blank");
		
		window.open(encodeURI(ctx+"/v1/pages/shop/shopIndex.jsp?"+exports.encodeParams("shopId="+shopId)),"_blank");
		
	};
	
	//跳转到商家列表
	exports.jumpToShopList=function(shopTypeId){
		
		//get2post(ctx+"/v1/pages/shop/shopList.jsp?shopTypeId="+shopTypeId,"_blank");
		//window.open(encodeURI(ctx+"/v1/pages/shop/shopList.jsp?"+exports.encodeParams("shopTypeId="+shopTypeId)),"_blank");
		
		window.location.href='?shopTypeId='+shopTypeId+'#ldhStoreList';
	
	};
	
	//批量替换
	String.prototype.replaceAll  = function(oldString,newString){     
	    return this.replace(new RegExp(oldString,"gm"),newString);     
	};
	
	//参数加密
	exports.encodeParams=function(params){
		
		if(validate.isNull(params))
			return;
		
		params="#"+params.toString()+"#";
		
		var length=params.length;
		
		
		if(length<5){
			params+="##%%#%";
			length+=6;
		}
			
		
		var str="";
		
		for(var i=0;i<length;i++){
			
			if(i%2==0){
				str+=params.substring(i,i+1)+"#";
			}else{
				
				str+=params.substring(i,i+1)+"%";
			}
			
		}
		return escape(str);
			
	};
	
	//参数解密
	exports.decodeParams=function(params){
		
		params=unescape(params);
		
		params=params.replaceAll("#","");
		
		params=params.replaceAll("%","");
		
		return params;
	};
	
	//四舍五入
	exports.Digit=function(digit, length) {
	    length = length ? parseInt(length) : 0;
	    if (length <= 0) return Math.round(digit);
	    digit = Math.round(digit * Math.pow(10, length)) / Math.pow(10, length);
	    return digit;
	};
	
	/**
	 * 获取参数
	 */
	exports.getParameter=function(key){
		
		return $("#"+key).val();
		
		/*var params=window.location.search;
		
		var paramsArray=new Array();
		
		var keysArray=new Array();
		
		var valuesArray=new Array();
		
		if(params.length>0){
			
			params=params.substring(1, params.length);
			
			if(params.indexOf("&")>=0){
				
				var mutiParams=params.split("&");
				
				for(var i=0;i<mutiParams.length;i++){
					
					paramsArray=mutiParams[i].split("=");
					
					keysArray[i]=paramsArray[0];
					
					valuesArray[i]=paramsArray[1];
				}
			}else{
				paramsArray=params.split("=");
				
				keysArray[0]=paramsArray[0];
				
				valuesArray[0]=paramsArray[1];
			}
			
		}
		for(var i=0;i<keysArray.length;i++){
			
			if(key==keysArray[i]){
				
				return valuesArray[i];
			}
			
		}
		return "";*/
	};
	
	
	 exports.getExplorerInfo=function() {
		 var explorer = window.navigator.userAgent.toLowerCase(),
		 ua = navigator.userAgent.toLowerCase();
		 //ie
		 if (explorer.indexOf("msie") >= 0) {
		    var ver=explorer.match(/msie ([\d.]+)/)[1];
		    return {type:"IE",version:ver};
		 }
		 //firefox
		 else if (explorer.indexOf("firefox") >= 0) {
		    var ver=explorer.match(/firefox\/([\d.]+)/)[1];
		    return {type:"Firefox",version:ver};
		 }
		 //Chrome
		 else if(explorer.indexOf("chrome") >= 0){
		    var ver=explorer.match(/chrome\/([\d.]+)/)[1];
		     return {type:"Chrome",version:ver};
		 }
		 //Opera
		 else if(explorer.indexOf("opera") >= 0){
		 var ver=explorer.match(/opera.([\d.]+)/)[1];
		 return {type:"Opera",version:ver};
		 }
		 //Safari
		 else if(explorer.indexOf("Safari") >= 0){
		 var ver=explorer.match(/version\/([\d.]+)/)[1];
		 return {type:"Safari",version:ver};
		 }
		 //UC
		 else if(explorer.indexOf("uc") >= 0){
		 var ver=explorer.match(/version\/([\d.]+)/)[1];
		 return {type:"UC",version:ver};
		 }
		 //weixin
		 else if(ua.match(/MicroMessenger/i)=="micromessenger"){
		 var ver=ua.match(/version\/([\d.]+)/)[1];
		 return {type:"MicroMessenger",version:ver};
		 }else{
			 
			 return {type:"other",version:""};
		 }
	}
	
	//转码
	exports.utf16to8=function(str) { 
		  var out, i, len, c;
		  out = "";
		  len = str.length;
		  for (i = 0; i < len; i++) {
		    c = str.charCodeAt(i);
		    if ((c >= 0x0001) && (c <= 0x007F)) {
		        out += str.charAt(i);
		    } else if (c > 0x07FF) {
		        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
		        out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
		        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
		    } else {
		        out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
		        out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
		    }
		  }
		  return out;
	};
	
	//页面跳转
	exports.showDiv=function(id,opt,params){
		
		hideMenu();
	
		if(!validate.isNull(opt)){
			
			exports.setOpt(opt);
		}
		if(validate.isNull(exports.getCookie("userId"))){
			
			if(validate.isNull(params)){
				window.location.href="#ldhLogin";
			}else{
				window.location.href=params+"#ldhLogin";
			}
			
			
			return;
		}
		
		window.location.href=id;
		
	};
	
	exports.setOpt=function(opt){
		
		this.opt=opt;
		
	};
	
	exports.getOpt=function(){
		
		return this.opt;
		
	};
	
	

	exports.getLocation=function() {
		
		if(validate.isNull(exports.getCookie("location"))){
			
			var geolocation = new BMap.Geolocation();
			geolocation.getCurrentPosition(function(r){
				if(this.getStatus() == BMAP_STATUS_SUCCESS){
					exports.setCookie("lat",r.point.lat);
					exports.setCookie("lng",r.point.lng);
					parseLngLat(r.point.lng,r.point.lat)
				}
				else {
					showTips('定位失败:'+this.getStatus());
				}        
			},{enableHighAccuracy: true})
		}else{
			
			
			$("#ldhHome .header_fixed h1 a").html(exports.getCookie("location"));
			//因PC端需要 7、23 号所加
			$(".headerAddress ul").html(exports.getCookie("location"));
			$("#ldhLocation .location_top span:eq(0)").html(exports.getCookie("location"));
			
			document.title="云便利"
			//exports.cancelLoading();//将加载隐藏 7、23 号所加
		}
		
		
	}
	
	exports.refreshLocation=function() {
			exports.showLoading();
			var geolocation = new BMap.Geolocation();
			geolocation.getCurrentPosition(function(r){
				if(this.getStatus() == BMAP_STATUS_SUCCESS){
					exports.setCookie("lat",r.point.lat);
					exports.setCookie("lng",r.point.lng);
					parseLngLat(r.point.lng,r.point.lat,"refresh")
					exports.cancelLoading();
				}
				else {
					showTips('定位失败:'+this.getStatus());
				}        
			},{enableHighAccuracy: true})
		
	}
	
	function parseLngLat(lng,lat,opt){
		
		if(validate.isNull(lng) || validate.isNull(lat))
		   return;
		
		// 百度地图API功能
		var point = new BMap.Point(lng,lat);
		var geoc = new BMap.Geocoder();    
			geoc.getLocation(point, function(rs){
				var addComp = rs.addressComponents;
				//alert(addComp.province + ", " + addComp.city + ", " + addComp.district + ", " + addComp.street + ", " + addComp.streetNumber);
				
				$("#ldhHome .header_fixed h1 a").html(addComp.province+addComp.city+addComp.district+addComp.street+addComp.streetNumber);
				if(opt=="refresh"){
					$("#ldhLocation .location_top span:eq(0)").html(addComp.province+addComp.city+addComp.district+addComp.street+addComp.streetNumber);
					$("#ldhLocation .header_fixed em").html(addComp.city);
				}
				exports.setCookie("location",addComp.province+addComp.city+addComp.district+addComp.street+addComp.streetNumber);
				exports.setCookie("city",addComp.city);
				
			});   
   }
	exports.getLocation();
	//微信初始化
	exports.wxConfig=function(){
		
		

		var params={
				url:current_url
			};
		
		eval(Wind.compile("async", function() {

			var data = $await(async.DDF_AsyncRequest("POST",ctx+"/shopapp/Share/wxConfig.do", params));

		
			if(data.code == "1"){
				 // 加载一个模块
				  require.async(['http://res.wx.qq.com/open/js/jweixin-1.0.0.js'], function(wx) {
					  
					  wx.config({
					      debug: false,
					      appId: data["appId"],
					      timestamp: data["timestamp"],
					      nonceStr: data["nonceStr"],
					      signature:data["signature"],
					      jsApiList: [
					                  'checkJsApi',
					                  'onMenuShareTimeline',
					                  'onMenuShareAppMessage',
					                  'onMenuShareQQ',
					                  'onMenuShareWeibo',
					                  'hideMenuItems',
					                  'showMenuItems',
					                  'hideAllNonBaseMenuItem',
					                  'showAllNonBaseMenuItem',
					                  'translateVoice',
					                  'startRecord',
					                  'stopRecord',
					                  'onRecordEnd',
					                  'playVoice',
					                  'pauseVoice',
					                  'stopVoice',
					                  'uploadVoice',
					                  'downloadVoice',
					                  'chooseImage',
					                  'previewImage',
					                  'uploadImage',
					                  'downloadImage',
					                  'getNetworkType',
					                  'openLocation',
					                  'getLocation',
					                  'hideOptionMenu',
					                  'showOptionMenu',
					                  'closeWindow',
					                  'scanQRCode',
					                  'chooseWXPay',
					                  'openProductSpecificView',
					                  'addCard',
					                  'chooseCard',
					                  'openCard'
					      ]
					  });
					
					 
					   wx.ready(function () {
						   //发送给朋友
						   wx.onMenuShareAppMessage({
							      title: '云便利',
							      desc: '云便利商店，您身边的淘宝。它囊括了您身边的超市、便利店、食店、生鲜店、家政服务等各种社区生活服务商家，走到哪里都可以帮您精准找到身边的店铺，为您提供近距离、快速送货的轻松购物体验。',
							      link: 'http://www.storeme.cn/mall/v1/h5/pages/index.jsp',
							      imgUrl: 'http://www.storeme.cn/mall/v1/h5/img/logo.png',
							      trigger: function (res) {
							        // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
							        //alert('用户点击发送给朋友');
							      },
							      success: function (res) {
							    	  showTips("分享成功");
							      },
							      cancel: function (res) {
							    	  showTips("已取消分享");
							      },
							      fail: function (res) {
							    	  showTips(JSON.stringify(res));
							      }
							    });
						    //分享到朋友圈
						    wx.onMenuShareTimeline({
						        title: '云便利',
						        link: 'http://www.storeme.cn/mall/v1/h5/pages/index.jsp',
						        imgUrl: 'http://www.storeme.cn/mall/v1/h5/img/logo.png',
						        trigger: function (res) {
						          // 不要尝试在trigger中使用ajax异步请求修改本次分享的内容，因为客户端分享操作是一个同步操作，这时候使用ajax的回包会还没有返回
						        	//showTips('用户点击分享到朋友圈');
						        },
						        success: function (res) {
						          //alert('已分享');
						        	showTips("分享成功");
						        },
						        cancel: function (res) {
						          //alert('已取消');
						        	showTips("已取消分享");
						        },
						        fail: function (res) {
						         // alert(JSON.stringify(res));
						        	showTips(JSON.stringify(res));
						        }
						      });
						    //分享到QQ
						    wx.onMenuShareQQ({
						        title: '云便利',
						        desc: '云便利商店，您身边的淘宝。它囊括了您身边的超市、便利店、食店、生鲜店、家政服务等各种社区生活服务商家，走到哪里都可以帮您精准找到身边的店铺，为您提供近距离、快速送货的轻松购物体验。',
						        link: 'http://www.storeme.cn/mall/v1/h5/pages/index.jsp',
						        imgUrl: 'http://www.storeme.cn/mall/v1/h5/img/logo.png',
						        trigger: function (res) {
						         
						        },
						        complete: function (res) {
						        	showTips(JSON.stringify(res));
						        },
						        success: function (res) {
						        	showTips("分享成功");
						        },
						        cancel: function (res) {
						        	showTips("已取消分享");
						        },
						        fail: function (res) {
						        	showTips(JSON.stringify(res));
						        }
						      });
						  }); 
					   
					   wx.error(function (res) {
						   //alert(res.errMsg);
						   showTips(res.errMsg);
						 });
				  });
				
			}else{
				
				
				
			}
			

		}))().start();
		
	};
	
	//exports.wxConfig();

});